import socket
import threading

def thr_socket(socket_talk):
    while True:
        #一定记得写recv的大小
        rec_data = socket_talk.recv(1024)
        if rec_data:
            rec_content = rec_data.decode('GBK')
            print(rec_content)
            send_cont = 'hello from server'
            send_data = send_cont.encode('GBK')
            socket_talk.send(send_data)
        else:
            print('客户端已断开')
            break
    socket_talk.close()


if __name__ == '__main__':
    socket_server=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
    socket_server.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,True)
    socket_server.bind(('',9090))
    socket_server.listen(128)
    while True:
        socket_talk, ip_port = socket_server.accept()
        thr=threading.Thread(target=thr_socket,args=(socket_talk,))
        thr.start()
    socket_server.close()